from functools import cmp_to_key
from typing import List


class Solution:
    def largestNumber(self, nums: List[int]) -> str:
        ss = list(map(lambda x: str(x), nums))
        # ss.sort()

        def cmp(x, y):
            xx = x+y
            yy = y+x
            return int(xx) - int(yy)
        ss = sorted(ss, key=cmp_to_key(cmp))
        ss.reverse()
        ans = ''.join(ss)
        la = len(ans)
        i = 0
        while i < la and ans[i] == '0':
            i += 1
        if i:
            return ans[i-1:]

        return ans[i:]


solve = Solution()

questions = [
    ([10, 2],),
    ([3, 30, 34, 5, 9],),
    ([0, 0],),
]

for qi, q in enumerate(questions):
    print(f'#{qi}:', q)
    print('ans:', solve.largestNumber(q[0]))

